﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace CalmNine.Framework
{
    /// <summary>
    /// byte扩展类
    /// </summary>
    public static class ByteExtension
    {
        /// <summary>
        /// 是否相等
        /// </summary>
        /// <param name="bytes"></param>
        /// <param name="bytes1"></param>
        /// <returns></returns>
        public static bool Equal(this byte[] bytes, byte[] bytes1)
        {
            if (bytes1 == null && bytes1 == null)
            {
                return true;
            }
            if (bytes != null && bytes1 == null)
            {
                return false;
            }
            if (bytes == null && bytes1 != null)
            {
                return false;
            }
            if (bytes.Length != bytes1.Length)
            {
                return false;
            }
            for (int i = 0; i < bytes.Length; i++)
            {
                if (bytes[i] != bytes1[i])
                {
                    return false;
                }
            }

            return true;
        }

        /// <summary>
        /// byte[]转SByte[]
        /// </summary>
        /// <param name="bytes"></param>
        /// <returns></returns>
        public static SByte[] ToSBytes(this byte[] bytes)
        {
            SByte[] arr = new SByte[bytes.Length];
            Buffer.BlockCopy(bytes, 0, arr, 0, bytes.Length);
            return arr;
        }

        /// <summary>
        /// byte[]转SByte[]
        /// </summary>
        /// <param name="bytes"></param>
        /// <returns></returns>
        public static byte[] ToBytes(this SByte[] bytes)
        {
            byte[] arr = new byte[bytes.Length];
            Buffer.BlockCopy(bytes, 0, arr, 0, bytes.Length);
            return arr;
        }
    }
}